﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WebEntities;
using WebEntities.Models.Framework;

namespace com.subb.WebFramework
{
    public class FW_SiteArgsDAL
    {
        public FW_SiteArgs GetWebConfig(int id)
        {
            using (SugardbEntities ctx = new SugardbEntities())
            {
                ctx.ContextOptions.LazyLoadingEnabled = false;
                FW_SiteArgs args = ctx.FW_SiteArgs.FirstOrDefault(c => c.ArgID == id);
                return args;
            }
        }

        public int SaveWebConfig(WebsiteConfig webcfg)
        {
            int result = 0;
            using (SugardbEntities ctx = new SugardbEntities())
            {
                FW_SiteArgs sargs = ctx.FW_SiteArgs.FirstOrDefault(c => c.ArgID == webcfg.ArgID);
                if (sargs == null)
                {
                    sargs = new FW_SiteArgs();
                    sargs.BackgroundImage = webcfg.BackgroundImage;
                    sargs.BackgroundRepeat = webcfg.BackgroundRepeat;
                    ctx.FW_SiteArgs.AddObject(sargs);
                    result = sargs.ArgID;
                }
                else
                {
                    sargs.BackgroundImage = webcfg.BackgroundImage;
                    sargs.BackgroundRepeat = webcfg.BackgroundRepeat;
                }
                ctx.SaveChanges();
            }
            return result;
        }
    }
}
